package graph.impl;

import edu.princeton.cs.introcs.In;
import edu.princeton.cs.introcs.StdOut;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class StringGraphDFS {
	
	private Map<String,Boolean> visited = null;
	private StringGraph graph = null;
	
	public StringGraphDFS(StringGraph graph, String sourceVertex) {
		this.graph = graph;
		visited = new HashMap<String, Boolean>();
		dfs(sourceVertex);
	}

	public void dfs(String sourceVertex){
		Set<String> edges = graph.getEdges(sourceVertex);
		this.visited.put(sourceVertex, Boolean.TRUE);
		for(String edge : edges){
			if(visited.get(edge) == null){
				dfs(edge);
			}
		}
	}
	
	public static void main(String[] args) {
		In in = new In(args[0]);
		StringGraph stringGraph = new StringGraph(in);
		StringGraphDFS dfs = new StringGraphDFS(stringGraph,"RAJINI");
		if(dfs.visited.size() == stringGraph.vertexCount) {
			StdOut.println(dfs.visited);
		}
	}
}
